package com.jboa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jboa.dao.IEmployeeDAO;
import com.jboa.service.IEmployeeService;
import com.jboa.vo.SysDepartment;
import com.jboa.vo.SysEmployee;
@Service("employeeService")
public class EmployeeServiceImpl implements IEmployeeService {
	@Autowired
	@Qualifier("employeeDao")
	private IEmployeeDAO employeeDao;
	
	/**
	 * 登录
	 * @throws Exception 
	 */
	public SysEmployee login(SysEmployee employee) throws Exception {
		
		try {
			List<SysEmployee> emls=employeeDao.getByID(employee);
			if(emls==null||emls.size()!=1){
				return null;
			}
			return emls.get(0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new Exception("登录过程错误！");
		}
	}
	
	
	/**
	 * 注册
	 * @throws Exception 
	 */
	public boolean register(SysEmployee employee) throws Exception {
		
		try {
			employeeDao.save(employee);
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new Exception("注册错误！");
		}
	}
	
	/**
	 * 获取下一个处理报销单的人
	 */
	public SysEmployee getNextDealEmployee(String position, SysDepartment dept) {
		return employeeDao.getByDeptAndPosition(position, dept);
	}
	
	/**
	 * 根据id获取员工信息
	 */
	public SysEmployee getBysn(SysEmployee employee) {
		List<SysEmployee> emp=employeeDao.getByID(employee);
		if(emp!=null&&emp.size()>0){
			return emp.get(0);
		}
		return null;
	}

}
